package com.cat.model.biz.logic.impl;

import org.springframework.stereotype.Service;

import com.cat.model.biz.logic.SmsLogic;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.request.AlibabaAliqinFcTtsNumSinglecallRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
import com.taobao.api.response.AlibabaAliqinFcTtsNumSinglecallResponse;

/**
 * 
 * 
 */
@Service("smsLogic")
public class SmsLogicImpl implements SmsLogic{

    //阿里大鱼
    private static final String Url = "http://gw.api.taobao.com/router/rest";
    private static final String AppKey           = "23537619";
    private static final String AppSecret         = "eb8b79e287cf083d419f146d8b425454";         

    @Override
	public void doSendSms(String phone, String ttsPrams, String smsFreeSignName, String smsTemplateCode) {
		AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
    	req.setSmsType("normal");
    	req.setSmsParam(ttsPrams);
    	req.setRecNum(phone);
    	
    	req.setSmsFreeSignName(smsFreeSignName);
    	req.setSmsTemplateCode(smsTemplateCode);
    	
    	try {
    		TaobaoClient client = new DefaultTaobaoClient(Url, AppKey, AppSecret);
    		AlibabaAliqinFcSmsNumSendResponse response = client.execute(req);
    		//LoggerManager.common.info("sms|send_result|" + response.getBody());
		} catch (ApiException e) {
			//LoggerManager.common.error("sms|send_error|" + e.getMessage(), e);
		}
	}
	
    @Override
	public void doSendCall(String phone, String ttsPrams, String calledShowNum, String ttsCode) {
		TaobaoClient client = new DefaultTaobaoClient(Url, AppKey, AppSecret);
    	AlibabaAliqinFcTtsNumSinglecallRequest req = new AlibabaAliqinFcTtsNumSinglecallRequest();
    	req.setTtsParam(ttsPrams);
    	req.setCalledNum(phone);
    	
    	req.setCalledShowNum(calledShowNum);
    	req.setTtsCode(ttsCode);
    	try {
			AlibabaAliqinFcTtsNumSinglecallResponse response = client.execute(req);
			//LoggerManager.common.info("sms|call_result" + response.getBody());
		} catch (ApiException e) {
			//LoggerManager.common.error("sms|call_error|" + e.getMessage(), e);
		}
	}
    
}
